﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.WarehouseManage;
using ProduceBasicData.Api.DTO.WarehouseDto;
using ProduceBasicData.Domain.WarehouseManage;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.WarehouseManage
{
    /// <summary>
    /// 仓库控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehouseController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public WarehouseController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 创建仓库
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateWarehouse(CreateWarehouseCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取仓库列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<WarehouseDto>> GetWarehouseList([FromQuery] GetWarehouseCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 更新仓库
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateWarehouse(UpdateWarehouseCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除仓库
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteWarehouse(DeleteWarehouseCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 仓库批量删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeWarehouse(DeleteRangeWarehouseCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 获取仓库下拉框数据
        /// </summary>
        /// <returns>仓库列表</returns>
        [HttpGet]
        public async Task<ApiResult<List<Warehouse>>> GetWarehouseDropdown()
        {
            GetWarehouseDropdownCommand request = new GetWarehouseDropdownCommand();
            return await _mediator.Send(request);
        }
    }
}
